package com.zoroki.student_score_system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zoroki.student_score_system.domain.Score;
import com.zoroki.student_score_system.service.ScoreService;
import com.zoroki.student_score_system.utils.Msg;
import com.zoroki.student_score_system.vo.Result;
import com.zoroki.student_score_system.vo.ScoreVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/score")
public class ScoreController {
    @Autowired
    ScoreService scoreService;

    @GetMapping("/getAllScore")
    public @ResponseBody Result<Page<ScoreVo>> getAllScore(int pageNo, int pageSize, String msg, String type) {
        return new Result<Page<ScoreVo>>(0,scoreService.getAllScore(pageNo,pageSize,msg,type), Msg.SUCCESS);
    }

    @GetMapping("/getScoreByStudentId")
    public @ResponseBody Result<List<Score>> getScoreByStudentId(int studentId) {
        return new Result<List<Score>>(0,scoreService.getScoreByStudentId(studentId), Msg.SUCCESS);
    }

    @GetMapping("/getScoreByStudentIdAndCourseId")
    public @ResponseBody Result<Score> getScoreByStudentIdAndCourseId(int studentId, int courseId) {
        return new Result<Score>(0,scoreService.getScoreByStudentIdAndCourseId(studentId,courseId), Msg.SUCCESS);
    }


    @PostMapping("/addScore")
    public @ResponseBody Result<Boolean> addScore(@RequestBody Score score) {
        return new Result<Boolean>(0,scoreService.addScore(score), Msg.SUCCESS);
    }

    @PostMapping("/updateScore")
    public @ResponseBody Result<Boolean> updateScore(@RequestBody Score score) {
        System.out.println(score);
        return new Result<Boolean>(0,scoreService.updateScore(score), Msg.SUCCESS);
    }

    @PostMapping("/deleteScore")
    public @ResponseBody Result<Boolean> deleteScore(Integer scoreId) {
        return new Result<Boolean>(0,scoreService.deleteScore(scoreId), Msg.SUCCESS);
    }

}
